<?php

class SezonaModel extends NObject
{
	private $table = 'dbo.Sezona';
	private $connection;


	public static function initialize()
	{
		dibi::connect(NEnvironment::getConfig('database'));
	}
	
	public function __construct()
	{
		$this->connection = dibi::getConnection();
	}
	//-----------
	//FIND ALL
	//-----------	
	public function findAll()
	{
		return $this->connection->select('*')->from($this->table);
	}
	//-----------
	//FIND BY ID
	//-----------
	public function findById($id)
	{
		return $this->connection->query("SELECT [*] FROM ".$this->table." WHERE id=%i",$id);
		//return $this->connection->select('*')->from($this->table)->where('id=%i',$id);
	}
	//-----------
	//UPDATE
	//-----------
	public function update($id, array $data)
	{
		return $this->connection->update($this->table, $data)->where('id=%i', $id)->execute();
	}
	//-----------
	//INSERT
	//-----------	
	public function insert(array $data)
	{
		return $this->connection->insert($this->table, $data)->execute(dibi::IDENTIFIER);
	}
	//-----------
	//FIND ALL
	//-----------
	public function delete($id)
	{
		return $this->connection->query("DELETE FROM ".$this->table." WHERE id=%i", $id);
		//return $this->connection->delete($this->table)->where('id=%i', $id)->execute();
	}


}
